package com.sl.ms.carriage.handler;

import cn.hutool.core.util.ObjectUtil;
import com.sl.ms.base.api.common.AreaFeign;
import com.sl.ms.carriage.domain.constant.CarriageConstant;
import com.sl.ms.carriage.domain.dto.WaybillDTO;
import com.sl.ms.carriage.entity.CarriageEntity;
import com.sl.ms.carriage.service.CarriageService;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 跨省
 */
@Order(400) //定义顺序
@Component
public class TransProvinceChainHandler extends AbstractCarriageChainHandler {
    @Resource
    private CarriageService carriageService;
    @Resource
    private AreaFeign areaFeign;
    @Override
    public CarriageEntity doHandler(WaybillDTO waybillDTO) {
        CarriageEntity carriageEntity = null;
        Long receiverProvinceId = this.areaFeign.get(waybillDTO.getReceiverCityId()).getParentId();
        Long senderProvinceId = this.areaFeign.get(waybillDTO.getSenderCityId()).getParentId();
        if (ObjectUtil.equal(receiverProvinceId, senderProvinceId))
        {
            carriageEntity = this.carriageService.findEconomicCarriage(receiverProvinceId, senderProvinceId);
        }
        if (carriageEntity != null)
        {
            return carriageEntity;
        }
        return doNextHandler(waybillDTO);
    }

//    @Resource
//    private CarriageService carriageService;
//
//    @Override
//    public CarriageEntity doHandler(WaybillDTO waybillDTO) {
//        CarriageEntity carriageEntity = this.carriageService.findByTemplateType(CarriageConstant.TRANS_PROVINCE);
//        return doNextHandler(waybillDTO, carriageEntity);
//    }
}
